﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ODataRegression.Framework.Core.TestOM;
using ODataRegression.Framework.Core.MetaDataOM;
using ODataRegression.Framework.Core.Shared;
using System.Text.RegularExpressions;
using System.ComponentModel;
using System.Xml;
using ODataTestFrameworkCore.shared;

namespace ODataRegression.Framework.Core.Factories
{
    public class ODataSelectTestFactory : ODataTestFactoryBase
    {
        //int maxTestGenerationCount;
        //int generatedTestCount;
        //Regex verificationToken;
        public override List<ODataTest> CreateTestList()
        {
            //List<ODataTest> testList = new List<ODataTest>();
            EntityBaseURL = entitySet.URL;
            QueryURLBase = EntityBaseURL + "?$select=";
            testName = ODataTestNames.Select;
            testTile = "Verify that $select is working for selected entity";

            //verificationToken = new Regex("<m:properties>");
            // If test type not defined in config then return null
            string columnList = string.Empty;
            if (this.ISAvtiveTest)
            {
                maxTestGenerationCount = GetMaxTestGenerationCount();
                
                foreach (ODataEntityProperty item in entitySet.Entity.Properties)
                {
                    //Generate test for each single column
                    FinalQueryURL = QueryURLBase + item.Name + "&$top=1";
                    FinalQueryURL = URLMappers.ApplyConfigMappingActions(FinalQueryURL);
                    base.CreateTestList();
                    
                    generatedTestCount++;
                    if (generatedTestCount >= maxTestGenerationCount)
                    {
                        break;
                    }
                }

                // Create a test with all column selected 
                FinalQueryURL = QueryURLBase + entitySet.Entity.PropertyList + "&$top=1";
                FinalQueryURL = URLMappers.ApplyConfigMappingActions(FinalQueryURL);
                base.CreateTestList();
            }


           

            
        
            return testList;
        }

        public ODataSelectTestFactory(string serviceRoot, string ServiceName, ODataEntitySet entityset )
            : base(serviceRoot, ServiceName, entityset )
        {
            //this.entitySet = entityset;
            //this.ServiceName = ServiceName;
            //this.serviceRoot = serviceRoot;
            //this.testConfig = testConfig;

        }
    }
}
